﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SpreadsheetLight;
using DocumentFormat.OpenXml.Spreadsheet;

namespace SoftWareLab_Project
{
    public partial class data : System.Web.UI.Page
    {
        SertData sert = new SertData();
        int i = 0;
        private string User, TermFromSert, YearFromSert, No_Id;
        private double a = 0, b = 0, c = 0, d = 0, f = 0, g = 0, h = 0, l = 0, m = 0, n = 0, p = 0, q = 0, T1Work = 0.00, T2Work = 0.00, T3Work = 0.00, T4Work = 0.00, T5Work = 0.00, T6Work = 0.00;
        private string W11 = "0", W12 = "0", W13 = "0", W21 = "0", W22 = "0", W31 = "0", W32 = "0", W33 = "0", W34 = "0", W4 = "0", W5 = "0", W6 = "0" ,W1 ="0" ,W2 ="0" ,W3 ="0" ;
        protected void Page_Load(object sender, EventArgs e)
        {
            
            int term = 0,i;
            
            //string NAME_DEPARTMENT = Session["NAME_DEPARTMENT"].ToString();
            //string FName = Session["NAME"].ToString();
            //string LName = Session["LASTNAME"].ToString();
            //string P_TECHNICAL = Session["P_TECHNICAL"].ToString();

            if (!IsPostBack)
            {
                if (Session["User"]!= null)
                {
                    User = Session["User"].ToString();
                i = GetID(); 
                hdf_NO_ID.Value = i.ToString();

                lbYers.Text = Session["Year"].ToString();

                if (Session["Term"].ToString()=="1")
                {
                    term = 1;
                    lbTerm.Text = "ครั้งที่ 1 ตุลาคม - มีนาคม";
                }
                if (Session["Term"].ToString() == "2")
                {
                    term = 2;
                    lbTerm.Text = "ครั้งที่ 2 เมษายน - กันยายน";
                } 

                DataTable Table_Course = new DataTable();
                Table_Course = (DataTable)Session["Data_Course"];
                Gv_Course.DataSource = Table_Course;
                Gv_Course.DataBind();

                DataTable Table_Adviser = new DataTable();
                Table_Adviser = (DataTable)Session["Data_Adviser"];
                GV_Adviser.DataSource = Table_Adviser;
                GV_Adviser.DataBind();

                DataTable Table_CooperativeName = new DataTable();
                Table_CooperativeName = (DataTable)Session["Data_Cooperative"];
                GV_CooperativeName.DataSource = Table_CooperativeName;
                GV_CooperativeName.DataBind();

                DataTable Table_Reserch = new DataTable();
                Table_Reserch = (DataTable)Session["Data_Reserch"];
                Gv_ReSert.DataSource = Table_Reserch;
                Gv_ReSert.DataBind();

                DataTable Table_Print = new DataTable();
                Table_Print = (DataTable)Session["Data_Print"];
                Gv_Print.DataSource = Table_Print;
                Gv_Print.DataBind();

                DataTable Table_Board = new DataTable();
                Table_Board = (DataTable)Session["Data_Board"];
                GV_BoardReport.DataSource = Table_Board;
                GV_BoardReport.DataBind();

                DataTable Table_lecture = new DataTable();
                Table_lecture = (DataTable)Session["Data_lecture"];
                GV_Lecture.DataSource = Table_lecture;
                GV_Lecture.DataBind();

                DataTable Table_Proficient = new DataTable();
                Table_Proficient = (DataTable)Session["Data_Proficient"];
                GV_Profient.DataSource = Table_Proficient;
                GV_Profient.DataBind();

                DataTable Table_Other = new DataTable();
                Table_Other = (DataTable)Session["Data_Other"];
                GV_Other.DataSource = Table_Other;
                GV_Other.DataBind();

                DataTable Table_management = new DataTable();
                Table_management = (DataTable)Session["Table_management"];
                GV_management.DataSource = Table_management;
                GV_management.DataBind();

                DataTable Table_developer = new DataTable();
                Table_developer = (DataTable)Session["Table_developer"];
                GV_developer.DataSource = Table_developer;
                GV_developer.DataBind();

                DataTable Table_culture = new DataTable();
                Table_culture = (DataTable)Session["Table_culture"];
                GV_Culture.DataSource = Table_culture;
                GV_Culture.DataBind();

                InsertTotalWork inss = new InsertTotalWork();
                TWorkEntity WorkEn = new TWorkEntity();
                WorkEn.NoId = Convert.ToInt32(hdf_NO_ID.Value);
                WorkEn.UserName = User;
                WorkEn.Term = term;
                WorkEn.Years = lbYers.Text;
                WorkEn.TeachWork = float.Parse(T1Work.ToString());
                HTeachWork.Value = WorkEn.TeachWork.ToString();
                WorkEn.ReSerchWork = float.Parse(T2Work.ToString());
                HReSerchWork.Value = WorkEn.ReSerchWork.ToString();
                WorkEn.ServiceWork = float.Parse(string.Format("{0:F2}", T3Work));
                HServiceWork.Value = WorkEn.ServiceWork.ToString();
                WorkEn.Other = float.Parse((T4Work + T5Work + T6Work).ToString());
                HOther.Value = WorkEn.Other.ToString();
                   

                dataGridDetail();
                if (lbYers.Text == YearFromSert && term == Convert.ToInt32(TermFromSert))
                {
                    inss.Update(WorkEn,Convert.ToInt32(No_Id)); 
                }
                if (lbYers.Text != YearFromSert && term != Convert.ToInt32(TermFromSert))
                {
                    inss.Insertss(WorkEn); 
                } 
                }
                else
                {
                    Response.Redirect("Login.aspx");
                }
                    
            }   
        }
        private void dataGridDetail()
        {
            DataTable dt = sert.GetDataFromUsername(User);

            if (dt != null && dt.Rows.Count > 0)
            {
                No_Id = dt.Rows[0]["NO_ID"].ToString();
                TermFromSert = dt.Rows[0]["TERM"].ToString();
                YearFromSert = dt.Rows[0]["YEAR"].ToString();   
            }
        }
        private int GetID()
        {
            string strConnString = WebConfigurationManager.ConnectionStrings["DB_EVALUATEConnectionString"].ConnectionString;
            int id;
            string sqltext = @"SELECT ISNULL (MAX(NO_ID),0)
                                from TB_TOTALWORK";
            SqlCommand sqlcomm = new SqlCommand();
            SqlConnection sqlconn = new SqlConnection(strConnString);
            sqlcomm.Connection = sqlconn;
            sqlcomm.CommandType = System.Data.CommandType.Text;
            sqlcomm.CommandText = sqltext;
            try
            {
                sqlcomm.Connection.Open();
                id = (int)sqlcomm.ExecuteScalar() + 1;
            }
            catch (Exception)
            {

                sqlcomm.Connection.Close();
                sqlcomm.Connection.Dispose();
                throw;
            }
            sqlcomm.Connection.Close();
            sqlcomm.Connection.Dispose();
            return id;
        }
        protected void Gv_Course_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                i++;
                a += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "TotalJob"));
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                //e.Row.Font.Bold = true;
                e.Row.Cells[0].Text = "รวม";
                e.Row.Cells[11].Text = a.ToString("#,##0.00");
                W21 = b.ToString("#,##0.00");
                e.Row.Cells[11].HorizontalAlign = HorizontalAlign.Center;
                //e.Row.BackColor = Color.DeepSkyBlue;
                T2Work = T2Work + Convert.ToDouble(W21);

            }
        }

        protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                i++;
                b += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "TotalJob"));
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                //e.Row.Font.Bold = true;
                e.Row.Cells[0].Text = "รวม";
                e.Row.Cells[7].Text = b.ToString("#,##0.00");
                W21 =  b.ToString("#,##0.00");
                e.Row.Cells[7].HorizontalAlign = HorizontalAlign.Center;
                //e.Row.BackColor = Color.DeepSkyBlue;
                T2Work = T2Work + Convert.ToDouble(W21);

            }
        }

        protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                i++;
                c += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "TotalJob"));
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                //e.Row.Font.Bold = true;
                e.Row.Cells[0].Text = "รวม";
                e.Row.Cells[4].Text = c.ToString("#,##0.00");
                W22 = c.ToString("#,##0.00");
                e.Row.Cells[4].HorizontalAlign = HorizontalAlign.Center;
                //e.Row.BackColor = Color.DeepSkyBlue;
                T2Work = T2Work + Convert.ToDouble(W22);
            }
        }
        
        protected void GV_Adviser_RowDataBound(object sender, GridViewRowEventArgs e)
        {
           if (e.Row.RowType == DataControlRowType.DataRow)
            {
                i++;
                d += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "TotalJob"));
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                //e.Row.Font.Bold = true;
                e.Row.Cells[0].Text = "รวม";
                e.Row.Cells[6].Text = d.ToString("#,##0.00");
                W12 = d.ToString("#,##0.00");
                e.Row.Cells[6].HorizontalAlign = HorizontalAlign.Center;
                //e.Row.BackColor = Color.DeepSkyBlue;
                T1Work = T1Work + Convert.ToDouble(W12);
            }
        }

        protected void GV_CooperativeName_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                i++;
                f += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "TotalJob"));
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                //e.Row.Font.Bold = true;
                e.Row.Cells[0].Text = "รวม";
                e.Row.Cells[3].Text = f.ToString("#,##0.00");
                W13 = f.ToString("#,##0.00");
                e.Row.Cells[3].HorizontalAlign = HorizontalAlign.Center;
                //e.Row.BackColor = Color.DeepSkyBlue;
                T1Work = T1Work +  Convert.ToDouble(W13);
            }
        }

        protected void GV_BoardReport_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                i++;
                g += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "TotalJob"));
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                //e.Row.Font.Bold = true;
                e.Row.Cells[0].Text = "รวม";
                e.Row.Cells[3].Text = g.ToString("#,##0.00");
                W31= g.ToString("#,##0.00");
                e.Row.Cells[3].HorizontalAlign = HorizontalAlign.Center;
                //e.Row.BackColor = Color.DeepSkyBlue;
                T3Work = Convert.ToDouble((T3Work + Convert.ToDouble(W31)).ToString("#,##0.00"));
            }
        }

        protected void GV_Lecture_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                i++;
                h += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "TotalJob"));
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                //e.Row.Font.Bold = true;
                e.Row.Cells[0].Text = "รวม";
                e.Row.Cells[7].Text = h.ToString("#,##0.00");
                W32 = h.ToString("#,##0.00");
                e.Row.Cells[7].HorizontalAlign = HorizontalAlign.Center;
                //e.Row.BackColor = Color.DeepSkyBlue;
                T3Work = T3Work + Convert.ToDouble(W32);
            }
        }

        protected void GV_Profient_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                i++;
                l += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "TotalJob"));
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                //e.Row.Font.Bold = true;
                e.Row.Cells[0].Text = "รวม";
                e.Row.Cells[3].Text = l.ToString("#,##0.00");
                W33 = l.ToString("#,##0.00");
                e.Row.Cells[3].HorizontalAlign = HorizontalAlign.Center;
                //e.Row.BackColor = Color.DeepSkyBlue; 
                T3Work = T3Work + Convert.ToDouble(W33);
            }
        }

        protected void GV_Other_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                i++;
                m += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "TotalJob"));
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                //e.Row.Font.Bold = true;
                e.Row.Cells[0].Text = "รวม";
                e.Row.Cells[2].Text = m.ToString("#,##0.00");
                W34 = m.ToString("#,##0.00");
                e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Center;
                //e.Row.BackColor = Color.DeepSkyBlue;
                T3Work = T3Work + Convert.ToDouble(W34);
            }

        }

        protected void GV_Culture_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                i++;
                n += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "TotalJob"));
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                //e.Row.Font.Bold = true;
                e.Row.Cells[0].Text = "รวม";
                e.Row.Cells[2].Text = n.ToString("#,##0.00");
                W4= n.ToString("#,##0.00");
                e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Center;
                //e.Row.BackColor = Color.DeepSkyBlue;
                T4Work = T4Work + Convert.ToDouble(W4);
            }

        }

        protected void GV_developer_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                i++;
                p += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "TotalJob"));
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                //e.Row.Font.Bold = true;
                e.Row.Cells[0].Text = "รวม";
                e.Row.Cells[3].Text = p.ToString("#,##0.00");
                W5 = p.ToString("#,##0.00");
                e.Row.Cells[3].HorizontalAlign = HorizontalAlign.Center;
                //e.Row.BackColor = Color.DeepSkyBlue;
                T5Work = T5Work + Convert.ToDouble(W5);
            }
        }

        protected void GV_management_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                i++;
                q += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "TotalJob"));
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                //e.Row.Font.Bold = true;
                e.Row.Cells[0].Text = "รวม";
                e.Row.Cells[2].Text = q.ToString("#,##0.00");
                W6 = q.ToString("#,##0.00");
                e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Center;
               // e.Row.BackColor = Color.DeepSkyBlue;
                T6Work = T6Work + Convert.ToDouble(W6);
            }
        }

        protected void Imbt_Report_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["User"]!= null)
            {
                string NAME_DEPARTMENT = Session["NAME_DEPARTMENT"].ToString();
                string FName = Session["NAME"].ToString();
                string LName = Session["LASTNAME"].ToString();
                string P_TECHNICAL = Session["P_TECHNICAL"].ToString();
                string faculty = Session["NAME_FACULTY"].ToString();
                string Management = Session["P_MANAGEMENT"].ToString();
                string Year = Session["Year"].ToString();
                string Term = Session["Term"].ToString();
                string strStart = "", strEnd = "";

               

                SLPageSettings ps = new SLPageSettings();
                SLDocument sl = new SLDocument();

                /*กำหนดขนาดกระดาษ*/
                ps.PaperSize = SLPaperSizeValues.A4Paper;


                /*สร้าง Style */
                SLStyle style = sl.CreateStyle();
                SLStyle styleCenter = sl.CreateStyle();
                SLStyle styleLeft = sl.CreateStyle();
                SLStyle styleBold = sl.CreateStyle();
                SLStyle style3 = sl.CreateStyle();
                SLStyle styleCenterBold = sl.CreateStyle();
                SLStyle styleLeftBold = sl.CreateStyle();

                SLStyle styleBorderLeft = sl.CreateStyle();
                SLStyle styleBorderRight = sl.CreateStyle();
                SLStyle styleBorderTop = sl.CreateStyle();
                SLStyle styleBorderBottom = sl.CreateStyle();
                SLStyle styleBorder = sl.CreateStyle();
                SLStyle styleRight = sl.CreateStyle();

                SLStyle styleCenter14 = sl.CreateStyle();

                styleCenter14.Alignment.Horizontal = HorizontalAlignmentValues.Center;
                styleCenter14.Font.FontName = "Angsana New";
                styleCenter14.Font.FontSize = 14;

                styleLeft.Alignment.Horizontal = HorizontalAlignmentValues.Left;
                styleLeft.Font.FontName = "Angsana New";
                styleLeft.Font.FontSize = 16;

                styleCenter.Alignment.Horizontal = HorizontalAlignmentValues.Center;
                styleCenter.Font.FontName = "Angsana New";
                styleCenter.Font.FontSize = 16;


                styleRight.Alignment.Horizontal = HorizontalAlignmentValues.Right;
                styleRight.Font.FontName = "Angsana New";
                styleRight.Font.FontSize = 16;

                style.Alignment.Horizontal = HorizontalAlignmentValues.Left;
                style.Font.FontName = "Angsana New";
                style.Font.FontSize = 16;

                styleBold.Font.Bold = true;
                styleBold.Font.FontName = "Angsana New";
                styleBold.Font.FontSize = 16;

                styleCenterBold.Font.Bold = true;
                styleCenterBold.Alignment.Horizontal = HorizontalAlignmentValues.Center;
                styleCenterBold.Font.FontName = "Angsana New";
                styleCenterBold.Font.FontSize = 16;

                styleLeftBold.Font.Bold = true;
                styleLeftBold.Alignment.Horizontal = HorizontalAlignmentValues.Left;
                styleLeftBold.Font.FontName = "Angsana New";
                styleLeftBold.Font.FontSize = 16;

                //เส้นขอบซ้าย
                style.Border.LeftBorder.BorderStyle = BorderStyleValues.Thin;
                style.Border.LeftBorder.Color = System.Drawing.Color.Black;

                //เส้นล่าง
                style.Border.BottomBorder.BorderStyle = BorderStyleValues.Thin;
                style.Border.BottomBorder.Color = System.Drawing.Color.Black;

                //เส้นขอบขวา
                style.Border.RightBorder.BorderStyle = BorderStyleValues.Thin;
                style.Border.RightBorder.Color = System.Drawing.Color.Black;

                //เส้นขอบบน
                style.Border.TopBorder.BorderStyle = BorderStyleValues.Thin;
                style.Border.TopBorder.Color = System.Drawing.Color.Black;



                //เส้นขอบซ้าย-ขวา
                style3.Border.LeftBorder.BorderStyle = BorderStyleValues.Thin;
                style3.Border.RightBorder.BorderStyle = BorderStyleValues.Thin;
                style3.Border.RightBorder.Color = System.Drawing.Color.Black;




                //เส้นขอบซ้าย
                styleBorderLeft.Border.LeftBorder.BorderStyle = BorderStyleValues.Thin;
                styleBorderLeft.Border.LeftBorder.Color = System.Drawing.Color.Black;

                //เส้นล่าง
                styleBorderBottom.Border.BottomBorder.BorderStyle = BorderStyleValues.Thin;
                styleBorderBottom.Border.BottomBorder.Color = System.Drawing.Color.Black;

                //เส้นขอบขวา
                styleBorderRight.Border.RightBorder.BorderStyle = BorderStyleValues.Thin;
                styleBorderRight.Border.RightBorder.Color = System.Drawing.Color.Black;

                //เส้นขอบบน
                styleBorderTop.Border.TopBorder.BorderStyle = BorderStyleValues.Thin;
                styleBorderTop.Border.TopBorder.Color = System.Drawing.Color.Black;

                //เส้นขอบเต็ม
                styleBorder.Border.LeftBorder.BorderStyle = BorderStyleValues.Thin;
                styleBorder.Border.BottomBorder.BorderStyle = BorderStyleValues.Thin;
                styleBorder.Border.RightBorder.BorderStyle = BorderStyleValues.Thin;
                styleBorder.Border.TopBorder.BorderStyle = BorderStyleValues.Thin;
                styleBorder.Border.LeftBorder.Color = System.Drawing.Color.Black;

                //ลบเส้นขอบ
                SLStyle delLine = sl.CreateStyle();
                delLine.Border.TopBorder.BorderStyle = BorderStyleValues.None;

                //หลายบรรทัดในเซล
                SLStyle Multiline = sl.CreateStyle();
                Multiline.SetWrapText(true);
                Multiline.Font.FontName = "Angsana New";
                Multiline.Font.FontSize = 16;
                /*ส่วนหัวของรายงาน*/

                sl.SetCellValue("A1", "สรุปข้อมูลประกอบการประเมินผลการปฏิบัติราชการอาจารย์ผู้สอน ประจำปีงบประมาณ " + "2556");
                sl.MergeWorksheetCells("A1", "I1");
                sl.SetCellStyle("A1", styleCenter);
                sl.SetCellStyle("A1", styleBold);

                sl.SetCellValue("A2", "คณะ" + faculty + "  มหาวิทยาลัยเทคโนโลยีราชมงคลธัญบุรี ");
                sl.MergeWorksheetCells("A2", "I2");
                sl.SetCellStyle("A2", styleCenter);
                sl.SetCellStyle("A2", styleBold);

                sl.SetCellValue("A3", "ครั้งที่ " + Term + " ปีการศึกษา " + Year);
                sl.MergeWorksheetCells("A3", "I3");
                sl.SetCellStyle("A3", styleCenter);

                sl.SetCellValue("A5", "ชื่อ : " + FName + "   " + LName + "   ภาควิชา : " + NAME_DEPARTMENT);
                sl.MergeWorksheetCells("A5", "I5");
                sl.SetCellStyle("A5", styleCenter);

                sl.SetCellValue("A6", "ตำแหน่งวิชาการ : " + P_TECHNICAL + "     ตำแหน่งบริหาร : " + Management);
                sl.MergeWorksheetCells("A6", "I6");
                sl.SetCellStyle("A6", styleCenter);

                sl.SetCellValue("A8", "สรุปภาระงาน (ดูรายละเอียดการคิดภาระงานจาก www.ped.rmutt.ac.th)");
                sl.MergeWorksheetCells("A8", "I8");
                sl.SetCellStyle("A8", styleLeft);
                sl.SetCellStyle("A8", styleBold);

                /*ส่วนของสรุป หัวเรื่อง*/
                sl.MergeWorksheetCells("A9", "E9");
                sl.MergeWorksheetCells("F9", "G9");
                sl.MergeWorksheetCells("H9", "I9");
                sl.SetCellValue("A9", "งาน");
                sl.SetCellValue("F9", "ภาระงาน/สัปดาห์");
                sl.SetCellValue("H9", "ภาระงานขั้นต่ำ");
                sl.SetCellStyle("A9", styleCenterBold);
                sl.SetCellStyle("F9", styleCenterBold);
                sl.SetCellStyle("H9", styleCenterBold);
                // sl.SetCellStyle("A9", "I19", styleBorder);

                // WorkEn.TeachWork;
                // WorkEn.ReSerchWork;
                // WorkEn.ServiceWork;
                // WorkEn.Other;
                String strSum = "=SUM(";

                //------------------- 1 งานสอน ----------------------------//
                strStart = "A10"; strEnd = "E10";
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "1. งานสอน");
                sl.SetCellStyle(strStart, styleLeft);
                // "ภาระงาน/สัปดาห์
                strStart = "F10"; strEnd = "G10";
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValueNumeric(strStart, strSum);
                sl.SetCellStyle(strStart, styleCenter);
                //ภาระงานขั้นต่ำ
                strStart = "H10"; strEnd = "I10";
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "ไม่น้อยกว่า 18");
                sl.SetCellStyle(strStart, styleCenter);

                //------------------- 2 งานวิจัย ----------------------------//
                strStart = "A11"; strEnd = "E11";
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "2. งานวิจัย");
                sl.SetCellStyle(strStart, styleLeft);
                // "ภาระงาน/สัปดาห์
                strStart = "F11"; strEnd = "G11";
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValueNumeric(strStart, HReSerchWork.Value);
                sl.SetCellStyle(strStart, styleCenter);
                //ภาระงานขั้นต่ำ
                strStart = "H11"; strEnd = "I11";
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "ไม่น้อยกว่า 3.5");
                sl.SetCellStyle(strStart, styleCenter);

                //------------------- 3 งานบริการวิชาการ ----------------------------//
                strStart = "A12"; strEnd = "E12";
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "3. งานบริการวิชาการ");
                sl.SetCellStyle(strStart, styleLeft);
                // "ภาระงาน/สัปดาห์
                strStart = "F12"; strEnd = "G12";
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValueNumeric(strStart, HReSerchWork.Value);
                sl.SetCellStyle(strStart, styleCenter);
                //ภาระงานขั้นต่ำ
                strStart = "H12"; strEnd = "I12";
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "ไม่น้อยกว่า 3.5");
                sl.SetCellStyle(strStart, styleCenter);

                //------------------- 4 งานทำนุบำรุงศิลปวัฒนธรรม/งานพัฒนานักศึกษา/งานบริหาร/งานส่วนกลาง ----------------------------//
                strStart = "A13"; strEnd = "E13";
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "4. งานทำนุบำรุงศิลปวัฒนธรรม / งานพัฒนานักศึกษา /\n    งานบริหาร / งานส่วนกลาง");
                sl.SetCellStyle(strStart, Multiline);
                sl.SetRowHeight(13, 46.5);
                // "ภาระงาน/สัปดาห์
                strStart = "F13"; strEnd = "G13";
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValueNumeric(strStart, HOther.Value);
                sl.SetCellStyle(strStart, styleCenter);
                //ภาระงานขั้นต่ำ
                strStart = "H13"; strEnd = "I13";
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "ไม่น้อยกว่า 18");
                sl.SetCellStyle(strStart, styleCenter);

                //------------------- 5 รวม ----------------------------//
                strStart = "A14"; strEnd = "E14";
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "รวม");
                sl.SetCellStyle(strStart, styleCenter);
                // "ภาระงาน/สัปดาห์
                strStart = "F14"; strEnd = "G14";
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValueNumeric(strStart, "=sum(F10:F11:F12:F13)");
                sl.SetCellStyle(strStart, styleCenter);
                //ภาระงานขั้นต่ำ
                strStart = "H14"; strEnd = "I14";
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "ไม่น้อยกว่า 35");
                sl.SetCellStyle(strStart, styleCenter);

                //--------------------ตีเส้นขอบ-------------------------//
                strStart = "A9"; strEnd = "I14";
                sl.SetCellStyle(strStart, strEnd, styleBorder);


                //----------งานสอน รายละเอียด---------------------//
                strStart = "A16"; strEnd = "I16";
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "1. งานสอน");
                sl.SetCellStyle(strStart, styleCenterBold);

                strStart = "A17"; strEnd = "I17";
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "1.1 รายวิชาที่สอน");
                sl.SetCellStyle(strStart, styleLeftBold);

                /* --------------- ข้อมูล -----------------*/
                DataTable dt = new DataTable();
                dt = (DataTable)Session["Data_Course"];

                DataTable Table_Adviser = new DataTable();
                Table_Adviser = (DataTable)Session["Data_Adviser"];

                DataTable Table_CooperativeName = new DataTable();
                Table_CooperativeName = (DataTable)Session["Data_Cooperative"];

                DataTable Table_Reserch = new DataTable();
                Table_Reserch = (DataTable)Session["Data_Reserch"];

                DataTable Table_Print = new DataTable();
                Table_Print = (DataTable)Session["Data_Print"];

                DataTable Table_Board = new DataTable();
                Table_Board = (DataTable)Session["Data_Board"];

                DataTable Table_lecture = new DataTable();
                Table_lecture = (DataTable)Session["Data_lecture"];

                DataTable Table_Proficient = new DataTable();
                Table_Proficient = (DataTable)Session["Data_Proficient"];

                DataTable Table_Other = new DataTable();
                Table_Other = (DataTable)Session["Data_Other"];

                DataTable Table_management = new DataTable();
                Table_management = (DataTable)Session["Table_management"];

                DataTable Table_developer = new DataTable();
                Table_developer = (DataTable)Session["Table_developer"];

                DataTable Table_culture = new DataTable();
                Table_culture = (DataTable)Session["Table_culture"];

                int Row1 = 18;
                string nameObj = "",
                       edu = "",
                       Theory1 = "",
                       practice1 = "",
                       totalGrop = "",
                       totalStndent = "",
                       Course = "",
                       Coach_Tea = "",
                       Load_Unit = ""; 
                //----------- 1.1 รายวิชาที่สอน-------------------- -//
                if (dt.Rows.Count > 0)
                {
                    sl.SetColumnWidth("A1", 10.50);
                    sl.SetColumnWidth("B1", 10.25);
                    sl.SetColumnWidth("C1", 7.50);
                    sl.SetColumnWidth("D1", 7.50);
                    sl.SetColumnWidth("E1", 8.50);
                    sl.SetColumnWidth("F1", 9.00);
                    sl.SetColumnWidth("G1", 14.00);
                    sl.SetColumnWidth("H1", 8.00);
                    sl.SetColumnWidth("I1", 9.00);

                    for (int j = 0; j < dt.Rows.Count; j++)
                    {
                        nameObj = dt.Rows[j]["Name_Subject"].ToString();
                        edu = dt.Rows[j]["Degree"].ToString();
                        totalGrop = dt.Rows[j]["Student_Group"].ToString();
                        totalStndent = dt.Rows[j]["Student_Number"].ToString();
                        Theory1 = dt.Rows[j]["Theory_Student"].ToString();
                        practice1 = dt.Rows[j]["TB_practiceStudent"].ToString();
                        Course = dt.Rows[j]["Course"].ToString();
                        Coach_Tea = dt.Rows[j]["Coach_Tea"].ToString();
                        Load_Unit = dt.Rows[j]["TotalJob"].ToString();


                        strStart = "A" + Row1;
                        strEnd = "G" + Row1;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "" + (j + 1) + ".วิชา " + nameObj);
                        sl.SetCellStyle(strStart, styleLeft);

                        strStart = "H" + Row1;
                        strEnd = "I" + Row1;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "" + edu);
                        sl.SetCellStyle(strStart, styleCenter14);

                        Row1 += 1;

                        strStart = "A" + Row1;
                        sl.SetCellValue(strStart, "จำนวนักศึกษา");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "B" + Row1;
                        sl.SetCellValue(strStart, "" + totalGrop);
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "C" + Row1;
                        sl.SetCellValue(strStart, "กลุ่ม  รวม");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "D" + Row1;
                        sl.SetCellValue(strStart, "" + totalStndent);
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "E" + Row1;
                        sl.SetCellValue(strStart, "คน ทฤษฏี");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "F" + Row1;
                        sl.SetCellValue(strStart, "" + Theory1);
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "G" + Row1;
                        sl.SetCellValue(strStart, "คาบ/สัปดาห์  ปฏิบัติ");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "H" + Row1;
                        sl.SetCellValue(strStart, "" + practice1);
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "I" + Row1;
                        sl.SetCellValue(strStart, "คาบ/สัปดาห์");
                        sl.SetCellStyle(strStart, styleCenter14);

                        Row1 += 1;

                        strStart = "A" + Row1;
                        sl.SetCellValue(strStart, "" + Course);
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "B" + Row1;
                        sl.SetCellValue(strStart, "ประเภทการสอน");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "C" + Row1;
                        sl.SetCellValue(strStart, "" + Coach_Tea);
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "E" + Row1;
                        sl.SetCellValue(strStart, "ทฤษฏี");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "F" + Row1;
                        sl.SetCellValue(strStart, "");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "G" + Row1;
                        sl.SetCellValue(strStart, "คาบ/ภาคเรียน  ปฏิบัติ");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "H" + Row1;
                        sl.SetCellValue(strStart, "");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "I" + Row1;
                        sl.SetCellValue(strStart, "คาบ/ภาคเรียน");
                        sl.SetCellStyle(strStart, styleCenter14);

                        Row1 += 1;

                        strStart = "A" + Row1;
                        sl.SetCellValue(strStart, "ภาระงาน");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "B" + Row1;
                        sl.SetCellValueNumeric(strStart, "" + Load_Unit);
                        sl.SetCellStyle(strStart, styleCenter14);

                        strSum = strSum + strStart+":";

                        Row1 += 1;

                    }
                }

                /*------------------- 1.2 ที่ปรึกษาโครงงาน/วิทยานิพนธ์ -------------------*/

                strStart = "A" + Row1; strEnd = "I" + Row1;
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "1.2 ที่ปรึกษาโครงงาน/วิทยานิพนธ์");
                sl.SetCellStyle(strStart, styleLeftBold);
                Row1 += 1;
                string Subject_Adviser = "",
                       Adviser = "",
                       GroupNum_Adviser = "",
                       stdnum_Adviser = "",
                       Degree_adviser = "",
                       TotalJob = "";

                if (Table_Adviser.Rows.Count > 0)
                {
                    for (int j = 0; j < Table_Adviser.Rows.Count; j++)
                    {
                        Subject_Adviser = Table_Adviser.Rows[j]["Subject_Adviser"].ToString();
                        Adviser = Table_Adviser.Rows[j]["Adviser"].ToString();
                        GroupNum_Adviser = Table_Adviser.Rows[j]["GroupNum_Adviser"].ToString();
                        stdnum_Adviser = Table_Adviser.Rows[j]["stdnum_Adviser"].ToString();
                        Degree_adviser = Table_Adviser.Rows[j]["Degree_adviser"].ToString();
                        TotalJob = Table_Adviser.Rows[j]["TotalJob"].ToString();

                        strStart = "A" + Row1;
                        strEnd = "I" + Row1;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "" + (j + 1) + ".วิชา " + Subject_Adviser);
                        sl.SetCellStyle(strStart, styleLeft);

                        Row1 += 1;

                        strStart = "A" + Row1;
                        sl.SetCellValue(strStart, "จำนวนักศึกษา");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "B" + Row1;
                        sl.SetCellValue(strStart, "" + GroupNum_Adviser);
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "C" + Row1;
                        sl.SetCellValue(strStart, "กลุ่ม  รวม");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "D" + Row1;
                        sl.SetCellValue(strStart, "" + stdnum_Adviser);
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "E" + Row1;
                        sl.SetCellValue(strStart, "คน");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "F" + Row1;
                        sl.SetCellValue(strStart, "ระดับการศึกษา");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "G" + Row1;
                        sl.SetCellValue(strStart, "" + Degree_adviser);
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "H" + Row1;
                        sl.SetCellValue(strStart, "การให้คำปรึกษา");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "I" + Row1;
                        sl.SetCellValue(strStart, "" + Adviser);
                        sl.SetCellStyle(strStart, styleCenter14);

                        Row1 += 1;

                        strStart = "A" + Row1;
                        sl.SetCellValue(strStart, "ภาระงาน");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "B" + Row1;
                        sl.SetCellValueNumeric(strStart, "" + TotalJob);
                        sl.SetCellStyle(strStart, styleCenter14);
                        
                        strSum = strSum + strStart + ":";

                        Row1 += 1;
                    }
                }

                /*------------------ 1.3 สหกิจศึกษา -------------------*/

                strStart = "A" + Row1; strEnd = "I" + Row1;
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "1.3 สหกิจศึกษา");
                sl.SetCellStyle(strStart, styleLeftBold);
                Row1 += 1;

                string CooperativeName = "", TB_Cooperative_num = "";

                if (Table_CooperativeName.Rows.Count > 0)
                {
                    for (int j = 0; j < Table_CooperativeName.Rows.Count; j++)
                    {
                        CooperativeName = Table_CooperativeName.Rows[j]["CooperativeName"].ToString();
                        TB_Cooperative_num = Table_CooperativeName.Rows[j]["TB_Cooperative_num"].ToString();
                        TotalJob = Table_CooperativeName.Rows[j]["TotalJob"].ToString();

                        strStart = "A" + Row1;
                        strEnd = "F" + Row1;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "" + (j + 1) + ".ชื่อสถานประกอบการ " + CooperativeName);
                        sl.SetCellStyle(strStart, styleLeft);

                        strStart = "G" + Row1;
                        strEnd = "G" + Row1;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "จานวน น.ศ.");
                        sl.SetCellStyle(strStart, styleLeft);

                        strStart = "H" + Row1;
                        strEnd = "H" + Row1;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "" + TB_Cooperative_num);
                        sl.SetCellStyle(strStart, styleLeft);

                        strStart = "I" + Row1;
                        strEnd = "I" + Row1;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "คน");
                        sl.SetCellStyle(strStart, styleLeft);

                        Row1 += 1;

                        strStart = "A" + Row1;
                        sl.SetCellValue(strStart, "ภาระงาน");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "B" + Row1;
                        sl.SetCellValueNumeric(strStart, "" + TotalJob);
                        sl.SetCellStyle(strStart, styleCenter14);

                        strSum = strSum + strStart + ":";

                        Row1 += 1;

                    }
                }
                strSum = strSum + ")";

                /*---------------------- งานวิจัย --------------------*/
                int Row2 = Row1;
                strStart = "A" + Row2; strEnd = "I" + Row2;
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "2. งานวิจัย");
                sl.SetCellStyle(strStart, styleCenterBold);
                Row2 += 1;
                /*------------------- 2.1 โครงการวิจัย -----------------*/
                strStart = "A" + Row2; strEnd = "I" + Row2;
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "2.1 โครงการวิจัย");
                sl.SetCellStyle(strStart, styleLeftBold);
                Row2 += 1;

                string Projectname = "",
                       Projectpeople = "",
                       persenpj = "",
                       fundProject = "",
                       startpj = "",
                       endpj = "";

                if (Table_Reserch.Rows.Count > 0)
                {
                    for (int j = 0; j < Table_Reserch.Rows.Count; j++)
                    {
                        Projectname = Table_Reserch.Rows[j]["Projectname"].ToString();
                        Projectpeople = Table_Reserch.Rows[j]["Projectpeople"].ToString();
                        persenpj = Table_Reserch.Rows[j]["persenpj"].ToString();
                        fundProject = Table_Reserch.Rows[j]["fundProject"].ToString();
                        startpj = Table_Reserch.Rows[j]["startpj"].ToString();
                        endpj = Table_Reserch.Rows[j]["endpj"].ToString();
                        TotalJob = Table_Reserch.Rows[j]["TotalJob"].ToString();

                        strStart = "A" + Row2;
                        strEnd = "I" + Row2;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "" + (j + 1) + ".เรื่อง " + Projectname);
                        sl.SetCellStyle(strStart, styleLeft);

                        Row2 += 1;

                        strStart = "A" + Row2;
                        strEnd = "B" + Row2;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "" + Projectpeople);
                        sl.SetCellStyle(strStart, styleLeft);

                        strStart = "C" + Row2;
                        strEnd = "I" + Row2;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "แหล่งทุน : " + fundProject);
                        sl.SetCellStyle(strStart, styleLeft);

                        Row2 += 1;

                        strStart = "A" + Row2;
                        strEnd = "C" + Row2;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "เริ่มต้น : " + startpj);
                        sl.SetCellStyle(strStart, styleLeft);

                        strStart = "D" + Row2;
                        strEnd = "F" + Row2;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "สิ้นสุด : " + endpj);
                        sl.SetCellStyle(strStart, styleLeft);

                        strStart = "D" + Row2;
                        strEnd = "F" + Row2;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "สิ้นสุด : " + endpj);
                        sl.SetCellStyle(strStart, styleLeft);

                        strStart = "G" + Row2;
                        strEnd = "I" + Row2;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "เปอร์เซ็นมีส่วนร่วม : " + persenpj);
                        sl.SetCellStyle(strStart, styleLeft);

                        Row2 += 1;

                        strStart = "A" + Row2;
                        sl.SetCellValue(strStart, "ภาระงาน");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "B" + Row2;
                        sl.SetCellValue(strStart, "" + TotalJob);
                        sl.SetCellStyle(strStart, styleCenter14);

                        Row2 += 1;
                    }
                }

                /*------------------- 2.2 การตีพิมพ์ผลงาน -----------------*/
                strStart = "A" + Row2; strEnd = "I" + Row2;
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "2.2 การตีพิมพ์ผลงาน");
                sl.SetCellStyle(strStart, styleLeftBold);
                Row2 += 1;

                string Printname = "", PrintAt = "", PrintDate = "";
                if (Table_Print.Rows.Count > 0)
                {
                    for (int j = 0; j < Table_Print.Rows.Count; j++)
                    {
                        Printname = Table_Print.Rows[j]["Printname"].ToString();
                        PrintAt = Table_Print.Rows[j]["PrintAt"].ToString();
                        PrintDate = Table_Print.Rows[j]["PrintDate"].ToString();
                        TotalJob = Table_Print.Rows[j]["TotalJob"].ToString();


                        strStart = "A" + Row2;
                        strEnd = "I" + Row2;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "" + (j + 1) + ".เรื่อง " + Printname);
                        sl.SetCellStyle(strStart, styleLeft);

                        Row2 += 1;

                        strStart = "A" + Row2;
                        strEnd = "D" + Row2;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "วารสาร : " + PrintAt);
                        sl.SetCellStyle(strStart, styleLeft);

                        strStart = "E" + Row2;
                        strEnd = "I" + Row2;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "ตีพิมพ์เมื่อ : " + PrintDate);
                        sl.SetCellStyle(strStart, styleLeft);

                        Row2 += 1;

                        strStart = "A" + Row2;
                        sl.SetCellValue(strStart, "ภาระงาน");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "B" + Row2;
                        sl.SetCellValue(strStart, "" + TotalJob);
                        sl.SetCellStyle(strStart, styleCenter14);

                        Row2 += 1;


                    }
                }

                /*---------------------- 3. งานบริการวิชาการ --------------------*/
                int Row3 = Row2;
                strStart = "A" + Row3; strEnd = "I" + Row3;
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "3. งานบริการวิชาการ");
                sl.SetCellStyle(strStart, styleCenterBold);
                Row3 += 1;
                /*------------------- 3.1 เป็นคณะกรรมการ -----------------*/
                strStart = "A" + Row3; strEnd = "I" + Row3;
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "3.1 เป็นคณะกรรมการ");
                sl.SetCellStyle(strStart, styleLeftBold);
                Row3 += 1;

                string Boardname = "", Boardeorder = "";

                if (Table_Board.Rows.Count > 0)
                {
                    for (int j = 0; j < Table_Board.Rows.Count; j++)
                    {
                        Boardname = Table_Board.Rows[j]["Boardname"].ToString();
                        Boardeorder = Table_Board.Rows[j]["Boardeorder"].ToString();
                        TotalJob = Table_Board.Rows[j]["TotalJob"].ToString();

                        strStart = "A" + Row3;
                        strEnd = "F" + Row3;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "" + (j + 1) + "." + Boardname);
                        sl.SetCellStyle(strStart, styleLeft);

                        strStart = "G" + Row3;
                        strEnd = "I" + Row3;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "" + (j + 1) + "." + Boardeorder);
                        sl.SetCellStyle(strStart, styleLeft);

                        Row3 += 1;

                        strStart = "A" + Row3;
                        sl.SetCellValue(strStart, "ภาระงาน");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "B" + Row3;
                        sl.SetCellValue(strStart, "" + TotalJob);
                        sl.SetCellStyle(strStart, styleCenter14);

                        Row3 += 1;

                    }
                }

                /*------------------- 3.2 เป็นวิทยากร -----------------*/
                strStart = "A" + Row3; strEnd = "I" + Row3;
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "3.2 เป็นวิทยากร");
                sl.SetCellStyle(strStart, styleLeftBold);
                Row3 += 1;

                string lecturename = "",
                       Lecture = "",
                       Hour = "",
                       lecturedate = "",
                       lecturelocation = "",
                       lecturecredit = "";

                if (Table_lecture.Rows.Count > 0)
                {
                    for (int j = 0; j < Table_lecture.Rows.Count; j++)
                    {
                        lecturename = Table_lecture.Rows[j]["lecturename"].ToString();
                        Lecture = Table_lecture.Rows[j]["Lecture"].ToString();
                        Hour = Table_lecture.Rows[j]["Hour"].ToString();
                        lecturedate = Table_lecture.Rows[j]["lecturedate"].ToString();
                        lecturelocation = Table_lecture.Rows[j]["lecturelocation"].ToString();
                        lecturecredit = Table_lecture.Rows[j]["lecturecredit"].ToString();
                        TotalJob = Table_lecture.Rows[j]["TotalJob"].ToString();

                        strStart = "A" + Row3;
                        strEnd = "I" + Row3;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "" + (j + 1) + ". เรื่อง" + lecturename);
                        sl.SetCellStyle(strStart, styleLeft);

                        Row3 += 1;

                        strStart = "A" + Row3;
                        strEnd = "E" + Row3;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "เป็นวิทยากร" + Lecture);
                        sl.SetCellStyle(strStart, styleLeft);

                        strStart = "F" + Row3;
                        strEnd = "I" + Row3;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "จำนวนชั่วโมง" + Hour + " ชั่วโมง");
                        sl.SetCellStyle(strStart, styleLeft);

                        Row3 += 1;

                        strStart = "A" + Row3;
                        strEnd = "D" + Row3;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "วันที่ : " + lecturedate);
                        sl.SetCellStyle(strStart, styleLeft);

                        strStart = "E" + Row3;
                        strEnd = "I" + Row3;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "สถานที่" + lecturelocation);
                        sl.SetCellStyle(strStart, styleLeft);

                        Row3 += 1;

                        strStart = "A" + Row3;
                        strEnd = "I" + Row3;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "จัดโดย" + lecturecredit);
                        sl.SetCellStyle(strStart, styleLeft);

                        Row3 += 1;

                        strStart = "A" + Row3;
                        sl.SetCellValue(strStart, "ภาระงาน");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "B" + Row3;
                        sl.SetCellValue(strStart, "" + TotalJob);
                        sl.SetCellStyle(strStart, styleCenter14);

                        Row3 += 1;
                    }
                }

                /*------------------- 3.3 เป็นผู้ทรงคุณวุฒิ -----------------*/
                strStart = "A" + Row3; strEnd = "I" + Row3;
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "3.3 เป็นผู้ทรงคุณวุฒิ");
                sl.SetCellStyle(strStart, styleLeftBold);
                Row3 += 1;

                string Proficient = "", rbProficient = "";

                if (Table_Proficient.Rows.Count > 0)
                {
                    for (int j = 0; j < Table_Proficient.Rows.Count; j++)
                    {
                        Proficient = Table_Proficient.Rows[j]["Proficient"].ToString();
                        rbProficient = Table_Proficient.Rows[j]["rbProficient"].ToString();
                        TotalJob = Table_Proficient.Rows[j]["TotalJob"].ToString();

                        strStart = "A" + Row3;
                        strEnd = "I" + Row3;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "" + (j + 1) + ". เรื่อง" + Proficient);
                        sl.SetCellStyle(strStart, styleLeft);

                        Row3 += 1;

                        strStart = "A" + Row3;
                        strEnd = "I" + Row3;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "ตำแหน่ง : " + rbProficient);
                        sl.SetCellStyle(strStart, styleLeft);

                        Row3 += 1;

                        strStart = "A" + Row3;
                        sl.SetCellValue(strStart, "ภาระงาน");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "B" + Row3;
                        sl.SetCellValue(strStart, "" + TotalJob);
                        sl.SetCellStyle(strStart, styleCenter14);

                        Row3 += 1;

                    }
                }
                /*------------------- 3.4 อื่น ๆ -----------------*/
                strStart = "A" + Row3; strEnd = "I" + Row3;
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "3.4 อื่น ๆ");
                sl.SetCellStyle(strStart, styleLeftBold);
                Row3 += 1;

                string Other_Other = "";

                if (Table_Other.Rows.Count > 0)
                {
                    for (int j = 0; j < Table_Other.Rows.Count; j++)
                    {
                        Other_Other = Table_Other.Rows[j]["Other"].ToString();
                        TotalJob = Table_Other.Rows[j]["TotalJob"].ToString();

                        strStart = "A" + Row3;
                        strEnd = "I" + Row3;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "" + (j + 1) + ". เรื่อง" + Other_Other);
                        sl.SetCellStyle(strStart, styleLeft);

                        Row3 += 1;

                        strStart = "A" + Row3;
                        sl.SetCellValue(strStart, "ภาระงาน");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "B" + Row3;
                        sl.SetCellValue(strStart, "" + TotalJob);
                        sl.SetCellStyle(strStart, styleCenter14);

                        Row3 += 1;
                    }
                }

                /*---------------------- 4. งานทานุบารุงศิลปวัฒนธรรม (คณะกรรมการ/คณะทางาน) --------------------*/
                int Row4 = Row3;
                strStart = "A" + Row4; strEnd = "I" + Row4;
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "4. งานทำนุบารุงศิลปวัฒนธรรม (คณะกรรมการ/คณะทำงาน)");
                sl.SetCellStyle(strStart, styleCenterBold);
                Row4 += 1;
                string culture = "";

                if (Table_culture.Rows.Count > 0)
                {
                    for (int j = 0; j < Table_culture.Rows.Count; j++)
                    {
                        culture = Table_culture.Rows[j]["culture"].ToString();
                        TotalJob = Table_culture.Rows[j]["TotalJob"].ToString();

                        strStart = "A" + Row4;
                        strEnd = "I" + Row4;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "" + (j + 1) + ". เรื่อง" + Other_Other);
                        sl.SetCellStyle(strStart, styleLeft);

                        Row4 += 1;

                        strStart = "A" + Row4;
                        sl.SetCellValue(strStart, "ภาระงาน");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "B" + Row4;
                        sl.SetCellValue(strStart, "" + TotalJob);
                        sl.SetCellStyle(strStart, styleCenter14);

                        Row4 += 1;
                    }
                }

                /*----------------------5. งานพัฒนานักศึกษา (คณะกรรมการ/คณะทางาน/ที่ปรึกษานักศึกษา/ที่ปรึกษาชมรม) --------------------*/
                int Row5 = Row4;
                strStart = "A" + Row5; strEnd = "I" + Row5;
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "5. งานพัฒนานักศึกษา (คณะกรรมการ/คณะทางาน/ที่ปรึกษานักศึกษา/ที่ปรึกษาชมรม)");
                sl.SetCellStyle(strStart, styleCenterBold);
                Row5 += 1;

                string developer = "", rb_developer = "";

                if (Table_developer.Rows.Count > 0)
                {
                    for (int j = 0; j < Table_developer.Rows.Count; j++)
                    {
                        developer = Table_developer.Rows[j]["developer"].ToString();
                        rb_developer = Table_developer.Rows[j]["rb_developer"].ToString();
                        TotalJob = Table_developer.Rows[j]["TotalJob"].ToString();

                        strStart = "A" + Row5;
                        strEnd = "F" + Row5;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "" + (j + 1) + ". เรื่อง" + developer);
                        sl.SetCellStyle(strStart, styleLeft);

                        strStart = "G" + Row5;
                        strEnd = "I" + Row5;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "ตำแหน่ง" + rb_developer);
                        sl.SetCellStyle(strStart, styleLeft);

                        Row5 += 1;

                        strStart = "A" + Row5;
                        sl.SetCellValue(strStart, "ภาระงาน");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "B" + Row5;
                        sl.SetCellValue(strStart, "" + TotalJob);
                        sl.SetCellStyle(strStart, styleCenter14);

                        Row5 += 1;
                    }
                }

                /*----------------------6. งานบริหาร/งานส่วนกลาง (ดารงตาแหน่งต่างๆ/งานที่ได้รับมอบหมาย) --------------------*/
                int Row6 = Row5;
                strStart = "A" + Row6; strEnd = "I" + Row6;
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "6. งานบริหาร/งานส่วนกลาง (ดารงตาแหน่งต่างๆ/งานที่ได้รับมอบหมาย)");
                sl.SetCellStyle(strStart, styleCenterBold);
                Row6 += 1;

                string management = "";

                if (Table_management.Rows.Count > 0)
                {
                    for (int j = 0; j < Table_management.Rows.Count; j++)
                    {
                        management = Table_management.Rows[j]["management"].ToString();
                        TotalJob = Table_management.Rows[j]["TotalJob"].ToString();

                        strStart = "A" + Row6;
                        strEnd = "I" + Row6;
                        sl.MergeWorksheetCells(strStart, strEnd);
                        sl.SetCellValue(strStart, "" + (j + 1) + ". ดำรงตำแหน่ง : " + management);
                        sl.SetCellStyle(strStart, styleLeft);

                        Row6 += 1;

                        strStart = "A" + Row6;
                        sl.SetCellValue(strStart, "ภาระงาน");
                        sl.SetCellStyle(strStart, styleCenter14);

                        strStart = "B" + Row6;
                        sl.SetCellValue(strStart, "" + TotalJob);
                        sl.SetCellStyle(strStart, styleCenter14);

                        Row6 += 1;
                    }
                }

                strStart = "F" + Row6;
                strEnd = "I" + Row6;
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart,"ลงชื่อผู้รับการประเมิน.....................");
                sl.SetCellStyle(strStart, styleCenter14);

                Row6 += 1;
 
                strStart = "F" + Row6;
                strEnd = "I" + Row6;
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "(.....................................)");
                sl.SetCellStyle(strStart, styleCenter14);

                Row6 += 1;

                strStart = "F" + Row6;
                strEnd = "I" + Row6;
                sl.MergeWorksheetCells(strStart, strEnd);
                sl.SetCellValue(strStart, "วันที่...................................");
                sl.SetCellStyle(strStart, styleCenter14);
              

                /*----------------------------------------------------------------------------------------*/
                Response.Clear();
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("Content-Disposition", "attachment; filename=Subject.xlsx");
                sl.SaveAs(Response.OutputStream);
                Response.End();
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
           
        
        }

       
        
       
       
    }
}